import axios from "axios"
export default {
    state: {
        shopList: [],
        selectShopList: [],
        detailShopList: []
    },
    getters: {
        getShopListLeft(state) {
            return state.selectShopList.filter((item, index) => {
                return index % 2 == 0
            })
        },
        getShopListRight(state) {
            return state.selectShopList.filter((item, index) => {
                return index % 2 != 0
            })
        },
        getDetailShopList(state) {
            return state.detailShopList
        }
    },
    actions: {
        filterShopList(context, classify) {
            context.commit('FILTERSHOPLIST', classify)
        },
        getShop(context) {
            axios.get('/getShop').then(res => {
                context.commit('GETSHOP', res.data)
            })
        },
        getShopById(context, id) {
            context.commit('GETSHOPBYID', id)
        }
    },
    mutations: {
        FILTERSHOPLIST(state, classify) {
            if (classify) {
                state.selectShopList = state.shopList.filter((item) => {
                    return item.classify == classify
                })
            } else {
                state.selectShopList = state.shopList
            }
        },
        GETSHOP(state, data) {
            state.shopList = data
            state.selectShopList = data
        },
        GETSHOPBYID(state, id) {
            state.detailShopList = state.shopList.filter(item => {
                return item._id == id
            })
        }
    }
}